import Vue from 'vue'
import {
  SIDEBAR_TYPE,
  DEFAULT_THEME,
  DEFAULT_LAYOUT_MODE,
  DEFAULT_COLOR,
  DEFAULT_COLOR_WEAK,
  DEFAULT_FIXED_HEADER,
  DEFAULT_FIXED_SIDEMENU,
  DEFAULT_FIXED_HEADER_HIDDEN,
  DEFAULT_CONTENT_WIDTH_TYPE,
  DEFAULT_MULTI_PAGE,
  WSDZ_FLAG,
  WS_FLAG,
  CARD_HISTORYOBJ
} from "@/store/mutation-types"

const app = {
  state: {
    sidebar: {
      opened: true,
      withoutAnimation: false
    },
    device: 'desktop',
    theme: '',
    layout: '',
    contentWidth: '',
    fixedHeader: false,
    fixSiderbar: false,
    autoHideHeader: false,
    color: null,
    weak: false,
    multipage: true, //默认多页签模式
    chufangType:'1',
    worklingObj:{},//工作站
    huanzheToken:null,
    readCardStatus:null,
    weicaiSelected:false,
    wsTypeCode:'',//设置医保 读取信息类型
    wsflag:'',
    wsdzflag:'',
    loadingflag:false,
    readInfoObj:{},
    historyflag:'', //患者历史处方 点击应用后的 状态控制
    historyObj:'', //患者历史处方 点击应用后的 对象返回
    onlycardObj:{}, //卡密弹窗数据
    onlycardflag:false, //卡密弹窗 弹出状态
    guoqiAction:{}, //设置过期 状态的行为
    isOnlyService:null, //设置提交处方的对象，判断结算的时候 是否有 诊疗项目
    modalHaoCaiShow:false, //监听了 耗材详情弹窗是否关闭
    printNewArr:[
      {
        index:0,
        key:'pdwInfo',
        temp:'westernPrescriptionTmpl',
        defaultTemp:'chufang'
      },
      {
        index:1,
        key:'pdcInfo',
        temp:'chinesePrescriptionTmpl',
        defaultTemp:'chuchufangZhongyaofang'
      },
      {
        index:2,
        key:'treatmentInfo',
        temp:'treatmentTmpl',
        defaultTemp:'chufangZhiliao'
      },
      {
        index:3,
        key:'assayInfo',
        temp:'assayTmpl',
        defaultTemp:'chufanghuayan'
      },
      {
        index:4,
        key:'checkInfo',
        temp:'checkTmpl',
        defaultTemp:'chufangjiancha'
      },
      {
        index:5,
        key:'pmcInfo',
        temp:'consumableTmpl',
        defaultTemp:'chufangHaocaiold'
      },
      // {
      //   index:6,
      //   key:'pmsInfo',
      //   temp:'treatmentTmpl',
      //   defaultTemp:'chufangZhiliao2'
      // },
      // {
      //   index:6,
      //   key:'outpatientMedicalRecord',
      //   temp:'omrTmpl'
      // },
      // {
      //   index:7,
      //   key:'result',
      //   temp:'settlementTmpl'
      // }
    ],
    nocardFlag:false, //不带身份证 特殊 处理
    shownoCard: true, //不带身份证 显示
    globalVUEXInd: -1, //回车键逻辑处理
    rlwxtype:'cn.nhsa.ec.auth', //人脸ws处理步骤控制 
    shenheClose:0,
    

  },
  
  mutations: {
    SET_SHCLOSE: (state, flag) => {
      state.shenheClose++;
    },
    SET_MODALHOCAI: (state, flag) => {
      state.modalHaoCaiShow = flag
    },
    SET_RLWXTYPE: (state, flag) => {
      state.rlwxtype = flag
    },
    SET_GLOBALVUEXIND: (state, flag) => {
      state.globalVUEXInd = flag
    },
    SET_NOCARD_SHOW: (state, flag) => {
      state.shownoCard = flag
    },
    SET_NOCARD_STATUS: (state, flag) => {
      state.nocardFlag = flag
    },
    SET_ISONLYSER: (state, flag) => {
      state.isOnlyService = flag
    },
    SET_CQAC: (state, flag) => {
      state.guoqiAction = flag
    },
    SET_WSTYPE: (state, flag) => {
      state.wsTypeCode = flag
    },
    SET_ONLYCARDFLAG: (state, flag) => {
      state.onlycardflag = flag
    },
    SET_ONLYCARD: (state, flag) => {
      state.onlycardObj = flag
    },
    SET_HISTORY: (state, flag) => {
      state.historyflag = flag
    },
    SET_HISTORYOBJ: (state, flag) => {
      state.historyObj = flag
      Vue.ls.set(CARD_HISTORYOBJ, flag)
    },
    SET_READINFO: (state, obj) => {
      state.readInfoObj = obj
    },
    SET_LOADING_FLAG: (state, type) => {
      state.loadingflag = type
    },
    SET_WSDZ_FLAG: (state, type) => {
      state.wsdzflag = type
      Vue.ls.set(WSDZ_FLAG, type)
    },
    SET_WS_FLAG: (state, type) => {
      state.wsflag = type
      Vue.ls.set(WS_FLAG, type)
    },
    SET_RCARD_TOKEN: (state, type) => {
      state.readCardStatus = type
    },
    SET_WC_SELECTED: (state, type) => {
      state.weicaiSelected = type
    },
    SET_HZ_TOKEN: (state, type) => {
      state.huanzheToken = type
      if(type+'' === '555'){
        state.readCardStatus = ''
      }
    },
    SET_WORK_OBJ: (state, type) => {
      state.worklingObj = type
    },
    SET_CHUFANG_TYPE: (state, type) => {
      state.chufangType = type
    },
    SET_SIDEBAR_TYPE: (state, type) => {
      state.sidebar.opened = type
      Vue.ls.set(SIDEBAR_TYPE, type)
    },
    CLOSE_SIDEBAR: (state, withoutAnimation) => {
      Vue.ls.set(SIDEBAR_TYPE, true)
      state.sidebar.opened = false
      state.sidebar.withoutAnimation = withoutAnimation
    },
    TOGGLE_DEVICE: (state, device) => {
      state.device = device
    },
    TOGGLE_THEME: (state, theme) => {
      // setStore('_DEFAULT_THEME', theme)
      Vue.ls.set(DEFAULT_THEME, theme)
      state.theme = theme
    },
    TOGGLE_LAYOUT_MODE: (state, layout) => {
      Vue.ls.set(DEFAULT_LAYOUT_MODE, layout)
      state.layout = layout
    },
    TOGGLE_FIXED_HEADER: (state, fixed) => {
      Vue.ls.set(DEFAULT_FIXED_HEADER, fixed)
      state.fixedHeader = fixed
    },
    TOGGLE_FIXED_SIDERBAR: (state, fixed) => {
      Vue.ls.set(DEFAULT_FIXED_SIDEMENU, fixed)
      state.fixSiderbar = fixed
    },
    TOGGLE_FIXED_HEADER_HIDDEN: (state, show) => {
      Vue.ls.set(DEFAULT_FIXED_HEADER_HIDDEN, show)
      state.autoHideHeader = show
    },
    TOGGLE_CONTENT_WIDTH: (state, type) => {
      Vue.ls.set(DEFAULT_CONTENT_WIDTH_TYPE, type)
      state.contentWidth = type
    },
    TOGGLE_COLOR: (state, color) => {
      Vue.ls.set(DEFAULT_COLOR, color)
      state.color = color
    },
    TOGGLE_WEAK: (state, flag) => {
      Vue.ls.set(DEFAULT_COLOR_WEAK, flag)
      state.weak = flag
    },
    SET_MULTI_PAGE (state, multipageFlag) {
      Vue.ls.set(DEFAULT_MULTI_PAGE, multipageFlag)
      state.multipage = multipageFlag
    }
  },
  actions: {
    setReadInfo: ({ commit }, type) => {
      commit('SET_READINFO', type)
    },
    setLOADINGFlag: ({ commit }, type) => {
      commit('SET_LOADING_FLAG', type)
    },
    setWsDzFlag: ({ commit }, type) => {
      commit('SET_WSDZ_FLAG', type)
    },
    setWsFlag: ({ commit }, type) => {
      commit('SET_WS_FLAG', type)
    },
    setReadCard: ({ commit }, type) => {
      commit('SET_RCARD_TOKEN', type)
    },
    setWCSlected: ({ commit }, type) => {
      commit('SET_WC_SELECTED', type)
    },
    setHZToken: ({ commit }, type) => {
      commit('SET_HZ_TOKEN', type)
    },
    setWorkObj: ({ commit }, type) => {
      commit('SET_WORK_OBJ', type)
    },
    setChufangType: ({ commit }, type) => {
      commit('SET_CHUFANG_TYPE', type)
    },
    setSidebar: ({ commit }, type) => {
      commit('SET_SIDEBAR_TYPE', type)
    },
    CloseSidebar({ commit }, { withoutAnimation }) {
      commit('CLOSE_SIDEBAR', withoutAnimation)
    },
    ToggleDevice({ commit }, device) {
      commit('TOGGLE_DEVICE', device)
    },
    ToggleTheme({ commit }, theme) {
      commit('TOGGLE_THEME', theme)
    },
    ToggleLayoutMode({ commit }, mode) {
      commit('TOGGLE_LAYOUT_MODE', mode)
    },
    ToggleFixedHeader({ commit }, fixedHeader) {
      if (!fixedHeader) {
        commit('TOGGLE_FIXED_HEADER_HIDDEN', false)
      }
      commit('TOGGLE_FIXED_HEADER', fixedHeader)
    },
    ToggleFixSiderbar({ commit }, fixSiderbar) {
      commit( 'TOGGLE_FIXED_SIDERBAR', fixSiderbar)
    },
    ToggleFixedHeaderHidden({ commit }, show) {
      commit('TOGGLE_FIXED_HEADER_HIDDEN', show)
    },
    ToggleContentWidth({ commit }, type) {
      commit('TOGGLE_CONTENT_WIDTH', type)
    },
    ToggleColor({ commit }, color) {
      commit('TOGGLE_COLOR', color)
    },
    ToggleWeak({ commit }, weakFlag) {
      commit('TOGGLE_WEAK', weakFlag)
    },
    ToggleMultipage({ commit }, multipageFlag) {
      commit('SET_MULTI_PAGE', multipageFlag)
    }
  }
}

export default app